package com.pureut.quality.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.quality.domain.dto.QualityCheckDocDto;
import com.pureut.quality.domain.vo.QualityCheckDocVo;
import com.pureut.quality.service.IQualityCheckDocService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 检验单据配置
 * @Param
 * @Date 23-02-01
 * @Author hl
 **/
@RestController
@RequestMapping("/checkDoc")
public class QualityCheckDocController extends BaseController {

    @Resource
    private IQualityCheckDocService qualityCheckDocService;

    /**
     * 查询检验单据配置
     */
    @RequiresPermissions("quality:verifyconfig:inspecdocu:list")
    @GetMapping("/list")
    public TableDataInfo list(QualityCheckDocVo qualityCheckDocVo)
    {
        startPage();
        List<QualityCheckDocDto> list = qualityCheckDocService.selectCheckDocList(qualityCheckDocVo);
        return getDataTable(list);
    }

    /**
     * 新增检验单据配置
     */
    @RequiresPermissions("quality:verifyconfig:inspecdocu:add")
    @Log(title = "检验单据配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody QualityCheckDocVo qualityCheckDocVo){
        return toAjax(qualityCheckDocService.insertCheckDoc(qualityCheckDocVo));
    }

    /**
     * 批量删除检验单据配置
     */
    @RequiresPermissions("quality:verifyconfig:inspecdocu:remove")
    @Log(title = "检验单据配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{checkId}")
    public AjaxResult remove(@PathVariable("checkId") String checkId){
        return toAjax(qualityCheckDocService.deleteCheckDocById(checkId));
    }

    /**
     * 根据编号获取详细信息
     */
    @RequiresPermissions("quality:verifyconfig:inspecdocu:query")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable long checkId)
    {
        return AjaxResult.success(qualityCheckDocService.selectCheckDocById(checkId));
    }

    /**
     * 修改检验单据配置
     */
    @RequiresPermissions("quality:verifyconfig:inspecdocu:edit")
    @Log(title = "检验单据配置", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody QualityCheckDocVo qualityCheckDocVo){
            return toAjax(qualityCheckDocService.updateCheckDocEdit(qualityCheckDocVo));
    }

}
